package nbp.currency.logic;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesHelper {

	private static final String CONFIG_PROPERTIES = "config.properties";

	private static String URL_NBP;
	private static String URL_DIR_FILE;
	private static String RESOURCE_PATH;
	private static String EXTENSION;
	private static String DATE;
	private static String CHILDREN;
	private static String CURRENT_FILE;

	private Properties properties;

	public PropertiesHelper() {
		try {
			properties = getProperties();
		} catch (Exception e) {
			System.err.println("Blad przy pobieraniu pliku properties");
		}
		setPropertiesService();
	}

	private Properties getProperties() throws Exception {
		properties = new Properties();
		InputStream input = null;

		input = new FileInputStream(CONFIG_PROPERTIES);
		properties.load(input);

		if (input != null) {
			input.close();
		}
		return properties;
	}

	private void setPropertiesService() {
		URL_NBP = properties.getProperty("nbp.url");
		URL_DIR_FILE = properties.getProperty("nbp.url.dir");
		RESOURCE_PATH = properties.getProperty("resource.path");
		EXTENSION = properties.getProperty("resource.extension");
		DATE = properties.getProperty("xml.date.node");
		CHILDREN = properties.getProperty("xml.children.node");
		CURRENT_FILE = properties.getProperty("nbp.current.file");
	}

	public static String getCHILDREN() {
		return CHILDREN;
	}

	public static String getDATE() {
		return DATE;
	}

	public static String getEXTENSION() {
		return EXTENSION;
	}

	public static String getRESOURCE_PATH() {
		return RESOURCE_PATH;
	}

	public static String getURL_DIR_FILE() {
		return URL_DIR_FILE;
	}

	public static String getURL_NBP() {
		return URL_NBP;
	}
	
	public static String getCurrentFileName() {
		return CURRENT_FILE;
	}

}
